import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";

// Retrieve the information of objects belonging to an account,
// and filtered by type

async function getOwnedObjects(address: string, type: string) {
  const fullNodeUrl = getFullnodeUrl("mainnet");
  const client = new SuiClient({ url: fullNodeUrl });

  const objects = await client.getOwnedObjects({
    owner: address,
    options: { showDisplay: true, showType: true, showContent: true },
    filter: { StructType: type },
  });

  return objects.data.map((obj) => obj.data?.content);
}

const accountAddress =
  "0x51bfd0bf129e9323d891ccc66ec8a8c9a9947ee8dd1ae3742d33dfcca8b1e667";
const objectType =
  "0x2::coin::Coin<0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI>";
getOwnedObjects(accountAddress, objectType)
  .then(console.log)
  .catch(console.error);
